package net.lab1024.sa.base.module.support.rule.controller;

import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.module.support.rule.domain.entity.RuleCepStep;
import net.lab1024.sa.base.module.support.rule.service.RuleCepStepService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规则步骤 Controller
 */
@RestController
@RequestMapping("/rule/cep/step")
public class RuleCepStepController {

    @Autowired
    private RuleCepStepService ruleCepStepService;

    //@ApiOperation("保存规则步骤")
    @PostMapping("/save")
    public ResponseDTO<Boolean> save(@RequestBody RuleCepStep ruleCepStep) {
        boolean result = ruleCepStepService.save(ruleCepStep);
        return ResponseDTO.ok(result);
    }

    //@ApiOperation("更新规则步骤")
    @PostMapping("/update")
    public ResponseDTO<Boolean> update(@RequestBody RuleCepStep ruleCepStep) {
        boolean result = ruleCepStepService.update(ruleCepStep);
        return ResponseDTO.ok(result);
    }

    //@ApiOperation("删除规则步骤")
    @GetMapping("/delete/{id}")
    public ResponseDTO<Boolean> delete(@PathVariable("id") Long id) {
        boolean result = ruleCepStepService.deleteById(id);
        return ResponseDTO.ok(result);
    }

    //@ApiOperation("获取规则步骤详情")
    @GetMapping("/get/{id}")
    public ResponseDTO<RuleCepStep> getById(@PathVariable("id") Long id) {
        RuleCepStep ruleCepStep = ruleCepStepService.getById(id);
        return ResponseDTO.ok(ruleCepStep);
    }

    //@ApiOperation("获取规则的所有步骤")
    @GetMapping("/list/{ruleId}")
    public ResponseDTO<List<RuleCepStep>> getByRuleId(@PathVariable("ruleId") Long ruleId) {
        List<RuleCepStep> steps = ruleCepStepService.getByRuleId(ruleId);
        return ResponseDTO.ok(steps);
    }

    //@ApiOperation("批量保存规则步骤")
    @PostMapping("/batch-save/{ruleId}")
    public ResponseDTO<Boolean> batchSave(@PathVariable("ruleId") Long ruleId, 
                                        @RequestBody List<RuleCepStep> steps) {
        boolean result = ruleCepStepService.batchSave(ruleId, steps);
        return ResponseDTO.ok(result);
    }
} 